package com.xiaocheng.www.common.utils.http;

import lombok.Data;

@Data
public class AxiosResult<T>{
    private Integer code;
    private String msg;
    private T data;

    private AxiosResult(AxiosStatus axiosStatus) {
        this.code = axiosStatus.getCode();
        this.msg = axiosStatus.getMsg();
    }

    private AxiosResult(AxiosStatus axiosStatus, T data) {
                this(axiosStatus);
                this.data = data ;
    }



    /**
     * 成功只有状态码
     * @param
     * @return
     */
    public static<T> AxiosResult<T> success(){
        return new AxiosResult(AxiosStatus.OK);
    }

    /**
     * 成功带有信息
     * @param axiosStatus
     * @param object
     * @return
     */
    public static<T> AxiosResult<T> success(AxiosStatus axiosStatus,Object object){
        return new AxiosResult(axiosStatus.OK , object);
    }

    /**
     * 失败只有状态
     * @param
     * @return
     */
    public static<T> AxiosResult<T>  error(){
        return new AxiosResult(AxiosStatus.ERROR);
    }

    /**
     * 失败带有信息
     * @param axiosStatus
     * @param object
     * @return
     */
    public static<T> AxiosResult<T>  error(AxiosStatus axiosStatus,Object object){
        return new AxiosResult(axiosStatus.ERROR,object);
    }
}
